<template>
  <div class="test-container">
    <div class="top-main">
      <search :listQuery="listQuery" :path="$route.name"></search>
    </div>
    <div class="bottom-main">
      <div class="list-button-group">


        <div class="button-item">
          <el-button type="success" :disabled="selectrow.length == 1 ? false : true" icon="el-icon-document-copy"
            @click="examine('ok')">
            审核通过
          </el-button>
        </div>
        <div class="button-item">
          <el-button type="danger" :disabled="selectrow.length == 1 ? false : true" icon="el-icon-document-delete"
            @click="examine('no')">
            审核驳回
          </el-button>
        </div>
      </div>
      <div class="table-list">
        <el-table ref="tableSort" :data="list" :element-loading-text="elementLoadingText"
          @selection-change="setSelectRows" highlight-current-row height="100%" :header-cell-style="{
            'border-bottom': '1px solid #cbcccd',
            'border-top': '1px solid #cbcccd',
          }">
          <el-table-column show-overflow-tooltip type="selection" width="55" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="序号" width="95">
            <template #default="scope">
              {{ scope.$index + listQuery.pageSize * (listQuery.pageIndex - 1) + 1 }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="pingzhengh" label="凭证号" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="状态" prop="zhuangtai" align="center">
            <template #default="scope">
              {{ $util.getCkdbdZt(scope.row.zhuangtai) }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip label="物资区分" prop="wuziqfmc" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="物资分类" prop="wuzizymc" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="主管单位" prop="zhuguandwmc" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="发货单位" prop="fahuodw" align="center"></el-table-column>
          <!-- <el-table-column show-overflow-tooltip label="保障时效" prop="baozhangsx" align="center"></el-table-column> -->
          <el-table-column show-overflow-tooltip label="经办人" prop="jingbanr" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="创建时间" prop="create_time" width="200"
            align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="最后修改时间" prop="modify_time" width="200"
            align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="操作" fixed="right" min-width="80px">
            <template #default="{ row }">
              <el-button type="text" @click="showdetail(row)">明细</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination :background="background" :current-page="listQuery.pageIndex" :layout="layout"
        :page-size="listQuery.pageSize" :total="total" @current-change="handleCurrentChange"
        @size-change="handleSizeChange"></el-pagination>
    </div>

    <accept v-if="acceptshow" :gobacktitle="gobacktitle" :datarow="selectrow[0]"></accept>
    <detail v-if="detailshow" :gobacktitle="gobacktitle" :datarow="detailrow"></detail>
    <!-- 导入文件start -->
    <el-dialog :close-on-click-modal="false" :visible.sync="importShow" destroy-on-close title="导入文件" class="m-dialog"
      :append-to-body="true">
      <upload api-url="xqzdDetail/import" @success="uploadSuccess" />
    </el-dialog>
  </div>
</template>
<script>
import {
  QueryChukudbdPage,
  DelChukudbd,
  CkdbdSh,
  GetChukudbdPageByid
} from '@/api/exwarehouse'
let _listQuery = {
  pageIndex: 1,
  pageSize: 20,
  pingzhengh: '',
  wuziqfid: '',
  zhuguandwid: '',
  jingbanr: '',
  zhuangtai: '',
  create_time: '',
  zhuangtaiList: 1
}
import Upload from '@/components/Upload/upload'
import search from './components/search.vue'
import Accept from '../components/page1Accept.vue'
import Detail from './components/page3Detail.vue'
export default {
  name: 'Test',
  data() {
    return {
      listQuery: Object.assign({}, _listQuery),
      show: true,
      listLoading: true,
      total: 0,
      elementLoadingText: '正在加载...',
      list: [],
      layout: 'prev, pager, next, jumper',
      background: true,
      addshow: false,
      acceptshow: false,
      detailshow: false,
      importShow: false,
      gobacktitle: '',
      selectrow: [],
      detailrow: {},
    }
  },
  components: { Upload, search, Accept, Detail },
  created() {
    this.fetchData()
  },
  mounted() { },
  methods: {
    setSelectRows(val) {
      this.selectrow = val
      console.log(this.selectrow)
    },
    async fetchData() {
      let { data } = await QueryChukudbdPage(this.listQuery)
      this.list = data.rows
      this.total = data.total
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.listQuery.pageIndex = val
      this.fetchData()
    },
    add() {
      this.addshow = true
      this.gobacktitle = '新增'
    },
    edit() {
      this.addshow = true
      this.gobacktitle = '编辑'
    },
    accept() {
      this.acceptshow = true
      this.gobacktitle = '入库验收'
    },
    showdetail(row) {
      this.detailshow = true
      this.gobacktitle = '入库调拨单审核明细'
      this.detailrow = row
    },
    uploadSuccess() {
      this.importShow = false
    },
    uploadDB() {
      this.importShow = true
    },
    searchDbd() {
      this.listQuery.pageIndex = 1
      this.fetchData()
    },
    resetlist() {
      this.listQuery = Object.assign({}, _listQuery)
      this.fetchData()
    },
    async examine(type) {
      this.$confirm('确认审核当前选中的数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(async () => {
        let datarow = {
          id: this.selectrow[0].id,
          zhuangtai: type == 'ok' ? 3 : 2
        }
        let { data } = await CkdbdSh(datarow)
        this.fetchData()
        this.$message({
          message: '审核成功',
          type: 'success',
        })
      })
    }
  },
}
</script>
<style lang="scss" scoped>
.test-container {
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  background: #f6f8f9 !important;
  height: 100%;

  .top-main {
    width: 100%;
    background: #fff;
    padding: 10px 0;
  }

  .bottom-main {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    background-color: #fff;
    margin-top: 10px;
    padding-bottom: 10px;

    .list-button-group {
      display: flex;
      flex-direction: row;
      padding: 20px;

      .button-item {
        padding: 0px 10px;
      }

      .button-item:first-child,
      &:last-child {
        padding: 0px 10px 0 0;
      }
    }

    .table-list {
      flex: 1;
      padding: 0 20px 20px;
    }
  }

  .el-button {
    font-size: .14rem !important;
  }
}
</style>
